console.log("hello word!");
let arr = [1, 2, 3, 4, 5,607];
arr.forEach((item,index)=>{
    if (index > 3) {
        return;     //注意forEach不支持ruturn
    }
    console.log(item, index);})//es5用来快速遍历数组

for (let arrKey in arr) {
    console.log(arrKey); //数组私有属性也会遍历出来
    //console.log(arr[arrKey])
}
let person ={age:12, name: "jingfu"}
for (let personKey in person) { //es5用来遍历对象属性的
    console.log(person[personKey]);
}
console.log("--------------")
for (let value of arr) {   //es6提供专门用来遍历数组'支持return
    // if (value == 3)
    //     { // noinspection JSAnnotator
    //         return;
    //     }
    console.log(value);

}

let newArr = arr.filter(item=>item>3)
console.log(arr,newArr)
let newArr2=arr.map(item=>item+2)
console.log(arr,newArr2)
//console.log(false<5)
let result=arr.find(item=>{
    return item.toString().indexOf('7')>-1
})
console.log("find arr结果为："+result);

let isEixed = arr.some(item=>{
    return item==4
});
//console.log(arr.includes(4))

let sum=arr.reduce((previousValue, currentVal, index, arr) => {
    console.log(previousValue,currentVal,index,arr)
    //return total+=currentVal;
    return previousValue+currentVal; //return结果作为下一次total
    },0);
console.log("arr累加后结果为："+sum)

let fruits = [{'count':3,price:5},{'count':2,price:5},{'count':3,price:9}];
let prices = fruits.reduce((total,currentVal)=>{
    console.log(total,currentVal)
    return total+=currentVal.count*currentVal.price;
},0)
console.log('总价为：'+prices);

//利用reduce数组去重
let arr3 = [1, 2, 3, 4, 5, 2, 1];
let newArr3 = arr3.reduce((pre,cur)=>{
    console.log(pre,cur)
    if(!pre.includes(cur)){
        return pre.concat(cur)
    }else{
        return pre
    }
},[]);
console.log("arr2去重后结果为："+newArr3)
